package cn.northsea.mapper;

import cn.northsea.pojo.User;
import cn.northsea.pojo.UserVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
public interface UserMapper {

    @Select("select * from erp_user where user_username=#{userUsername} and user_password=#{userPassword}")
    User login(User user);

    @Select("select * from erp_user where user_id = #{userId}")
    User findUserById(Integer id);

    @Insert("insert into erp_user values (" +
            "null,#{userUsername},#{userPassword},#{userFullname},#{userPhone},#{userGender}" +
            ",#{userAge},#{userAddress},#{userStatus},#{deptId})")
    void addUser(User user);


    List<UserVo> findAll(@Param("likename") String likename, @Param("start") String start, @Param("end") String end);

    @Update("update erp_user \n" +
            "set user_username = #{userUsername},user_password = #{userPassword},user_fullname=#{userFullname}, user_phone=#{userPhone},user_gender=#{userGender},user_age=#{userAge},user_address=#{userAddress},user_status=0\n" +
            "where user_id=#{userId}")
    void updateUser(User user);

    @Select("select * from erp_user where user_username = #{value}")
    User check(String userUsername);

    @Insert("insert into erp_user values(null,#{userUsername}," +
            "#{userPassword},#{userFullname},#{userPhone}," +
            "#{userGender},#{userAge},#{userAddress},#{userStatus},#{deptId},#{createAt})")
    void register(User user);


    void delUser(Integer[] ids);

    @Update("update erp_user set user_status = 0 where user_id = #{value}")
    void huiFu(Integer userId);
}
